﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1.CookieDemo
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            HttpCookie cookie = new HttpCookie("CurrentUser", Server.UrlEncode(TextBox1.Text)) ;
            cookie.Expires = DateTime.Now.AddDays(2);
            //设置了有效期，持久性Cookie，否则是临时Cookie
            //持久性Cookie会存在客户端硬盘中，临时Cookie存在客户端内存中。
            Response.Cookies.Add(cookie);

            Response.Cookies["pwd"].Value = TextBox2.Text;
            Response.Cookies["pwd"].Expires = DateTime.Now.AddHours(2);

            Response.Redirect("WebForm2.aspx");
        }
    }
}